﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Payment
/// </summary>
public class Payment
{
    private string id = null;
    private string guid = null;
    private string from_account = null;
    private string creation_date = null;
    private string due_date = null;
    private string paid_date = null;
    private string status = null;
    private string type = null;
    private string amount = null;
    private string whom = null;
    private string comment = null;
    private Dictionary<Configuration.PaymentAttributes, string> dic;

    public string Id { get { return this.id; } set { this.id = value; } }
    public string Guid { get { return this.guid; } set { this.guid = value; } }
    public string FromAccount { get { return this.from_account; } set { this.from_account = value; } }
    public string CreationDate { get { return this.creation_date; } set { this.creation_date = value; } }
    public string DueDate { get { return this.due_date; } set { this.due_date = value; } }
    public string PaidDate { get { return this.paid_date; } set { this.paid_date = value; } }
    public string Status { get { return this.status; } set { this.status = value; } }
    public string Type { get { return this.type; } set { this.type = value; } }
    public string Amount { get { return this.amount; } set { this.amount = value; } }
    public string Whom { get { return this.whom; } set { this.whom = value; } }
    public string Comment { get { return this.comment; } set { this.comment = value; } }

    public Payment() { }

    public Payment(string id, string guid, string from_account, string creation_date,
                   string due_date, string paid_date, string status, string type,
                   string amount, string whom, string comment
                  )
    {
        this.id = id;
        this.guid = guid;
        this.from_account = from_account;
        this.creation_date = creation_date;
        this.due_date = due_date;
        this.paid_date = paid_date;
        this.status = status;
        this.type = type;
        this.amount = amount;
        this.whom = whom;
        this.comment = comment;
    }

    public Payment(Dictionary<Configuration.PaymentAttributes, string> values)
    {
        foreach (Configuration.PaymentAttributes att in values.Keys)
            switch (att)
            {
                case Configuration.PaymentAttributes.id: this.id = values[att];
                                                  break;
                case Configuration.PaymentAttributes.guid: this.guid = values[att];
                                                    break;
                case Configuration.PaymentAttributes.from_account: this.from_account = values[att];
                                                             break;
                case Configuration.PaymentAttributes.creation_date: this.creation_date = values[att];
                                                             break;
                case Configuration.PaymentAttributes.due_date: this.due_date = values[att];
                                                        break;
                case Configuration.PaymentAttributes.paid_date: this.paid_date = values[att];
                                                         break;
                case Configuration.PaymentAttributes.status: this.status = values[att];
                                                      break;
                case Configuration.PaymentAttributes.type: this.type = values[att];
                                                    break;
                case Configuration.PaymentAttributes.amount: this.amount = values[att];
                                                       break;
                case Configuration.PaymentAttributes.whom: this.whom = values[att];
                                                     break;
                case Configuration.PaymentAttributes.comment: this.comment = values[att];
                                                       break;  
            }
    }

    public static Payment newInstance(string[] values)
    {
        if (values.Length != Configuration.PaymentAttributesCount)
            return null;

        return new Payment(values[0], values[1], values[2], values[3], values[4], values[5],
                           values[6], values[7], values[8], values[9], values[10]
                          );
    }

    #region ISimpleObject<Account> Members

    public Dictionary<Configuration.PaymentAttributes, string> toDictionary()
    {
        dic = new Dictionary<Configuration.PaymentAttributes, string>();
        dic.Add(Configuration.PaymentAttributes.id, this.id);
        dic.Add(Configuration.PaymentAttributes.guid, this.guid);
        dic.Add(Configuration.PaymentAttributes.from_account, this.from_account);
        dic.Add(Configuration.PaymentAttributes.creation_date, this.creation_date);
        dic.Add(Configuration.PaymentAttributes.due_date, this.due_date);
        dic.Add(Configuration.PaymentAttributes.paid_date, this.paid_date);
        dic.Add(Configuration.PaymentAttributes.status, this.status);
        dic.Add(Configuration.PaymentAttributes.type, this.type);
        dic.Add(Configuration.PaymentAttributes.amount, this.amount);
        dic.Add(Configuration.PaymentAttributes.whom, this.whom);
        dic.Add(Configuration.PaymentAttributes.comment, this.comment);
        return dic;
    }

    public string[] toArray()
    {
        return this.toDictionary().Values.ToArray<string>();
    }

    #endregion
}
